<template>
	<div id="app">
		<van-loading size="2rem" vertical color="#1989fa" v-show="showLoading">加载中...</van-loading>
		<router-view v-show='!showLoading' />
	</div>
</template>

<script>
	let initShowLoading = false
	import {
		Toast
	} from 'vant'
	export default {
		name: 'App',
		data() {
			return {
				showLoading: initShowLoading
			}
		},
		created() {
			this.$axios.interceptors.request.use(config => {
				//请求前加加载效果
				//this.showLoading = true
				return config
			},err=>{
				//this.showLoading = false
			})
			this.$axios.interceptors.response.use((response) => {
				//this.showLoading = false
				if(response.status === 302){
					router.replace({
						path:'/login'
					})
				}
				return response;
			}, function(error) {
      alert(error.response.data.message)
				//initShowLoading = false
				if (302 === error.response.data.status) {
          this.$router.push({name:'login'})
					//window.location = '/login';
				} else {
					return Promise.reject(error);
				}
			});
		},
		watch: {
			$route: {
				deep: true,
				immediate: true,
				handler: function(value) {
					//跳到下一页时，页面回到顶部
					document.body.scrollTop = 0
					document.documentElement.scrollTop = 0
					//弹出退出提示
					let vm = this
					if (value.path === '/login' || value.path === '/main/index' || value.path === '/main/report' || value.path ===
						'/main/me') {
						var first = null;
						mui.back = function() {
							if (!first) {
								first = new Date().getTime();
								mui.toast('再按一次返回键退出应用');
								setTimeout(function() {
									first = null;
								}, 1000);
							} else {
								if (new Date().getTime() - first < 1000) {
									plus.runtime.quit();
								}
							}
						}
					}else {
						mui.back = function() {
							vm.$router.go(-1)
						}
					}
				}
			}
		}
	}
</script>

<style>
	.van-loading {
		margin-top: 50%;
	}

	.van-search__action {
		font-size: .88rem;
	}

	.report .van-tab {
		line-height: 1.56rem;
		padding: 0;
		margin-right: .5rem;
	}

	.report .van-tabs--line .van-tabs__wrap {
		height: 4rem;
	}

	.van-dropdown-menu__item {
		justify-content: left;
		padding-left: .6rem;
	}

	.gateWay .van-radio__label {
		margin-left: 1.5rem;
	}

	.van-dropdown-menu__title {
		line-height: 1.2rem;
	}

	/* .van-dropdown-menu__title::after {
		border: 0.18rem solid;
	} */
	.van-toast__icon {
		font-size: 2.5rem;
	}

	.van-toast {
		width: 5.62rem;
		line-height: 1.25rem;
		font-size: .82rem;
	}

	.van-field__left-icon .van-icon,
	.van-field__right-icon .van-icon {
		font-size: 1rem;
	}

	#app {
		margin-bottom: 4.37rem;
	}

	.deviceFault .van-dropdown-menu__title {
		font-size: .82rem;
	}

	.addCurMan [class*=van-hairline]::after,.addKeep [class*=van-hairline]::after,.addDevice [class*=van-hairline]::after,.deviceKeep [class*=van-hairline]::after,
	.index [class*=van-hairline]::after,
	.deviceFault [class*=van-hairline]::after {
		border: none;
	}

	.deviceKeep .van-field__left-icon .van-icon,
	.van-field__right-icon .van-icon {
		font-size: 1rem;
	}

	.van-cell--required::before {
		font-size: .88rem;
	}

	.van-cell__left-icon,
	.van-cell__right-icon {
		font-size: 1rem;
	}

	.van-nav-bar__arrow {
		font-size: 1rem;
	}

	.van-button {
		font-size: .8rem;
	}

	.van-nav-bar {
		height: 2.875rem;
		line-height: 2.875rem;
	}

	.van-cell {
		font-size: .8rem;
		padding: .8rem 1rem;
		line-height: 1.4rem;
	}

	.van-field__label {
		width: 5.62rem;
	}

	body {
		padding: 0;
		margin: 0;
		background: white;
	}

	.login .van-field__control {
		border-bottom: 1px solid #333;
	}

	.login .van-field__left-icon {
		margin-right: .7rem;
	}

	.main .van-tabbar-item__icon .van-icon {
		font-size: 1.3rem;
	}

	.main .van-tabbar-item__text {
		font-size: .86rem;
	}

	.index .van-grid-item__text {
		font-size: .78rem;
		color: #333333;
	}

	.van-nav-bar__title {
		font-size: .9rem;
	}

	.video-js .vjs-big-play-button {
		left: 37%;
		top: 35%;
		border: none;
	}
</style>
